<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>美滋滋饮品公司管理系统</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="./css/x-admin.css" media="all">
</head>

<body>
	<div class="x-body">
		<form class="layui-form" id="news-form" onsubmit="return false">
			<div class="layui-form-item">
				<label for="cname" class="layui-form-label"> ID </label>
				<div class="layui-input-inline">
					<input type="text" id="newsId" name="newsId" required=""
						lay-verify="required" autocomplete="off" value="1" readonly=""
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="cname" class="layui-form-label"> <span
					class="x-red">*</span>标题名
				</label>
				<div class="layui-input-inline">
					<input type="text" id="newsTitle" name="newsTitle" required=""
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label for="cname" class="layui-form-label"> <span
					class="x-red">*</span>内容
				</label>
				<div class="layui-input-inline">
					<input type="text" id="nwesContent" name="nwesContent" required=""
						lay-verify="required" autocomplete="off" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">所属分类</label>
				<div class="layui-input-inline">
					<select name="newsCategoryId">		
						<option value="0">--选择分类</option>					
						<option value="1">--行业新闻</option>
						<option value="2">--饮品百科</option>
						<option value="3">--公司新闻</option>
						<option value="4">--时事热点</option>
					</select>
				</div>
			</div>

			<div class="layui-form-item">
				<label for="L_repass" class="layui-form-label"> </label>
				<button onclick="updateNewsdetails()" class="layui-btn"
					lay-filter="save" lay-submit="">保存</button>
			</div>
		</form>
	</div>
	<script src="./lib/layui/layui.js" charset="utf-8">
		
	</script>
	<script src="./js/x-layui.js" charset="utf-8">
		
	</script>
	<script>
		var $ = null;
		var form = null;
		var layer = null;
		var upload = null;

		layui.use([ 'upload', 'form', 'layer' ], function() {
			$ = layui.jquery;
			form = layui.form;
			layer = layui.layer;
			upload = layui.upload;

			// jquery单位页面加载事件,也就是说当页面加载完毕之后自动触发其中的内容
			$(function() {
				getNewsById(); // 调用方法
			});

			
		});

		function getNewsById() {
			$.post("../adminNewsCategory?reqName=getNewsDetailsById", {
				newsId : sessionStorage.getItem("news")
			// 从浏览器会话中,通过键取出id值
			}, function(res) { // 回调函数,是当服务器响应之后会自动执行,其中res是服务器响应的数据
				
				$("#newsId").val(res.newsId); // 给文本框赋值
				$("#newsTitle").val(res.newsTitle);
				$("#nwesContent").val(res.nwesContent);
				$("#newsCategoryId").val(res.newsCategoryId);
			}, "json");
		}

		function updateNewsdetails() {
			var newsTitle = $("#newsTitle").val();//通过id获取文本框得值
			if (newsTitle == null || newsTitle == "") {
				return false;//代码停止
			}

			var nwesContent = $("#nwesContent").val();
			if (nwesContent == null || nwesContent == "") {
				return false;//代码停止
			}

			$.post("../adminNewsCategory?reqName=updateNewsDetailsById", $(
					"#news-form").serialize(), function(res) { // 回调函数,是当服务器响应之后会自动执行,其中res是服务器响应的数据
				if (res.success) {
					layer.msg(res.message);
					var index=parent.layer.getFrameIndex(window.name);
					parent.layer.close(index);//关闭弹框
					parent.mypage(); //调用父级的分页查询方法目的刷新表格
				} else {
					layer.msg(res.message);
				}
			}, "json");
		}
	</script>

</body>

</html>